package com.chenjie.drools.drl;

import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.internal.utils.KieHelper;

import java.util.List;
import java.util.Map;

public class DrlExecutor {
    private static DrlExecutor instance;

    public static DrlExecutor getInstance() {
        if (instance == null){
            instance = new DrlExecutor();
        }
        return instance;
    }

    public void  execute(String drl, List<Object> os){
        KieHelper helper = new KieHelper();
        helper.addContent(drl, ResourceType.DRL);
        KieSession kSession = helper.build().newKieSession();
        os.forEach(o->{
            kSession.insert(o);
        });
        kSession.fireAllRules();
        kSession.dispose();
    }
}
